<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Canvas</title>
    <style></style>
  </head>
  <body>
    <div class="container">
      <canvas id="demo"></canvas>
    </div>

    <script>
      ;(function () {
        const $canvas = document.querySelector('#demo')
        $canvas.width = 600
        $canvas.height = 600
        $canvas.style.border = '1px solid #cccccc'

        const context = $canvas.getContext('2d')

        const rectH = 10
        const rectW = 10
        // 路径宽
        context.lineWidth = 0.5

        for (let index = 0; index < $canvas.height / rectH; index++) {
          context.moveTo(0, index * rectH)
          context.lineTo($canvas.width, index * rectH)

          context.moveTo(index * rectW, 0)
          context.lineTo(index * rectW, $canvas.height)
        }

        context.strokeStyle = '#cccccc'

        context.stroke()
      })()
    </script>
  </body>
</html>
